package com.no1ikun.util;

import javax.swing.*;
import java.awt.*;

//封装一个自己定义的button
public class MyButton extends JButton {
    private String title;
    private int x;
    private int y;
    private int width;
    private int height;
    private Color color;

    private Color textColor;

    public MyButton(String title, int x, int y, int width, int height,Color color,Color textColor) {
        this.title = title;
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.color = color;
        this.textColor = textColor;
        init();
    }

    private  void init(){
        this.setText(title);
        //设置but显示的位置
        this.setBounds(x,y,width,height);
        this.setFont(new Font("宋体",Font.BOLD,16));
        //去掉边框
        this.setBorder(null);
        //去掉按钮文字的虚线
        this.setFocusPainted(false);
        //设置按钮的背景颜色
        this.setBackground(color);
        this.setForeground(textColor);
    }
}
